package view
{
	import data.Globals;
	
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import manager.MapConfig;
	
	import utils.LoaderManage;
	
	import view.other.LockView;
	
	public class LoginView extends Sprite
	{
		private var bg:Bitmap;
		
		private var startBtn:Sprite;
		
		private var lockView:LockView;
		
		public function LoginView()
		{
			if(stage)addToStage();
			else this.addEventListener(Event.ADDED_TO_STAGE,addToStage);
		}
		
		public function unlockNext():void{
			lockView.unlockNext();
		}
		
		private function addToStage(e:Event = null):void
		{
			this.removeEventListener(Event.ADDED_TO_STAGE,addToStage);
			LoaderManage.getInstance().loaderContent(Globals.RES_URL+"login.jpg",initBackground);	
			MapConfig.getInstance().loadXml("config");
			LoaderManage.getInstance().loaderContent(Globals.RES_URL+"Shooter.swf",complete);
		}		
		
		private function complete(event:Event):void
		{
			trace("Shooter.swf complete");
		}
		
		private function initBackground(event:Event):void
		{
			bg = event.target.content;
			bg.width = Globals.stage_width;
			bg.height = Globals.stage_height;
			this.addChild(bg);
			initLogin();
		}
		
		private function initLogin():void{
			lockView = new LockView(startGame);
			this.addChild(lockView);
		}
		
		private function startGame():void
		{
			if(this.parent){
				this.parent.removeChild(this);
			}
			Globals.towerWar.startGame();
		}
	}
}